<template>
    <div class="whitebg logincontainer">
        <div class="loginwarpper flexcenter flexcolumn">
            <div class="reg_title">修改密码</div>
            <!-- <div class="logintop">
                <img src="@/assets/images/loginbg.png" alt="" srcset="">
            </div> -->
            <div class="loginbox">
                <van-form class="loginboxform" @submit="onSubmit">
                    <!-- <van-field v-model="form.account" label="" :rules="[{ required: true, message: '请输入手机号码' }]" class="mb_12 " placeholder="请输入账号" /> -->
                    <van-field 
                        v-model="form.pass" 
                        :type="showpsd1?'':'password'" 
                        label="" 
                        :right-icon="showpsd1?'eye-o':'closed-eye'"
                        :rules="[{ required: true, message: '请填写新密码' },{pattern:/^.{6,18}$/, message:'密码长度必须为6-18个字符'}]" 
                        class="mb_12" 
                        placeholder="请输入新密码"
                        @click-right-icon="showPassword(1)" />
                    <van-field 
                        v-model="form.two_pass" 
                        :type="showpsd2?'':'password'" 
                        label="" 
                        :right-icon="showpsd2?'eye-o':'closed-eye'"
                        :rules="[{ required: true, message: '请填写确认密码' },{pattern:/^.{6,18}$/, message:'密码长度必须为6-18个字符'}]" 
                        class="borderinput" 
                        placeholder="请填写确认密码"
                        @click-right-icon="showPassword(2)" />
                    <!-- <div class="mt-80 loadbtn" @click="onSubmit">
                        <van-loading v-if='loading' type="spinner" size="16px" color="#fff"/> 
                        <span class="logintext"> 提 交 </span>
                    </div> -->
                    <van-button class="loadbtn" native-type="submit">
                        <van-loading v-if='loading' type="spinner" size="16px" color="#fff"  style="display:inline-block"/> 
                        <span class="logintext"> 注 册 </span>
                    </van-button>
                    <div class="flexcenter bottomspan">
                        <span class="commhover" @click="goPage('login')">返回登陆</span>
                    </div>
                </van-form>
            </div>
        </div>
    </div>
</template>

<script>
import PageBody from './PageBody.vue';
import { editUserPasswd } from '@/api/user';
import { Toast } from 'vant'
export default {
  data() {
    return {
      loading:false,
      form:{
        pass:'',
        two_pass:''
      },
      showpsd1:false,
      showpsd2:false,
    }
  },

  components:{
    PageBody
  },

  mounted() {
  },

  methods: {

    showPassword(type){
        if(type == 1){
            this.showpsd1 = !this.showpsd1
        }else{
            this.showpsd2 = !this.showpsd2
        }
    },

    goPage(page){
        this.$router.push({path:page})
    },

    onSubmit(){
        console.log('123123')
        if(this.form.pass!==this.form.two_pass){
            this.$toast('密码输入两次不一致！');
            return
        }
        this.loading = true;
        editUserPasswd(this.form).then(res=>{
            // if(res.code ==1){
            //     this.$toast('修改成功');
            //     this.$router.push({path:'/login'})
            // }
        })
    //   this.$store.dispatch('user/login',this.form).then(res=>{
    //     console.log('res:',res.code);
    //     if(res.code == 1){
    //       this.$router.push({ path: "/" });
    //     }else{
    //       console.log('失败',res.msg);
    //       console.log(Toast);
    //       Toast(res.msg);
    //     }
    //     this.loading = false;
    //   }).catch(e=>{
    //     this.loading = false;
    //   })
    },
  }
}
</script>
<style lang="scss">
.loginboxform{
    .van-cell{
        padding: 0;
        background-color: transparent;
    }
    .van-field__body{
        background-color: white;
        padding: 20px 32px;
        border-radius: 12px;
        border: 1px solid #eee;
    }
    .van-field__control{
        // border: 1px solid #000;
    }
    .van-cell::after{
        border: 0;
    }
    .van-field__error-message{
        padding-left:32px;
    }
     .van-button::before{
        background-color:transparent;
        border: 0;
    }
}
</style>
<style lang="scss" scoped>
.logincontainer{
  width: 100%;
  height: 100vh;
  
}
.loginwarpper{
    width: 100%;
    height: 100%;
    background: url('~@/assets/images/registerbg.png') center no-repeat;
    background-size: contain;
}
.reg_title{
    font-size: 44px;
    color: #000;
}
.loginbox{
    width: 100%;
    padding: 0 40px 40px;
    margin-top: 68px;
}
.loadbtn{
    margin-top: 60px;
    width: 100%;
    height: 80px;
    background: url('~@/assets/images/lgoinbg.png') center no-repeat ;
    background-size: contain;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    border: 0;
}
.logintext{
    margin-top: -10px;
}
.bottomspan{
    padding: 32px 36px 0;
    span{
        font-size: 28px;
    }
}
</style>
